<!-- create.sql -->
<!-- this script creates tables --> 
<!-- CS143 - Spring 2012 -->
<!-- 4/21/12 -->
<!-- programmers: Rhys Yu and Richard Lung -->

<html>
<head><title>Queries</title></head>
<body>

Type an SQL query in the following box:

<form method="GET">
<textarea input type="text" name="expr" rows="8" cols="60"></textarea><input type="submit" value="Submit">
</form>

The result of the query is :
<br><br>

<?php

$host_db = "localhost";
$username_db = "cs143";
$password_db = "";
$name_db = "CS143";

$link = mysql_connect($host_db, $username_db, $password_db);
mysql_select_db($name_db, $link);

if(!$link) {
    $errmsg = mysql_error($link);
    print "Connection failed: $errmsg <br />";
    exit(1);
}

$query = $_GET["expr"];
$result = mysql_query($query, $link);

if ($result && mysql_num_rows($result)) {
      $numrows = mysql_num_rows($result);
      $rowcount = 1;
     
  
      while ($row = mysql_fetch_assoc($result)) {
          echo "Row $rowcount<br />";
  
          while(list($var, $val) = each($row)) {
              print "<B>$var</B>: $val<br />";
          }
  
          echo "<br />";
          ++$rowcount;
      }
}

mysql_close($link);

?>

</body>
</html>
